package cn.tedu.ivos.geofence.service.impl;

import cn.tedu.ivos.geofence.mapper.GeofenceMapper;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceQuery;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceSavaParam;
import cn.tedu.ivos.geofence.pojo.entity.Geofence;
import cn.tedu.ivos.geofence.pojo.vo.GeofenceVO;
import cn.tedu.ivos.geofence.service.GeofenceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class GeofenceServiceImpl implements GeofenceService {
    @Autowired
    GeofenceMapper geofenceMapper;


    @Override
    public List<GeofenceVO> selectGeofence(GeofenceQuery geofenceQuery) {
        log.debug("查询围栏业务:geofenceQuery={}", geofenceQuery);
        List<GeofenceVO> list = geofenceMapper.selectGeofence(geofenceQuery);
        return list;
    }

    @Override
    public void saveGeofence(GeofenceSavaParam geofenceSavaParam) {
        log.debug("保存围栏业务:geofenceSavaParam={}", geofenceSavaParam);
        Geofence geofence = new Geofence();
        BeanUtils.copyProperties(geofenceSavaParam, geofence);
        if(geofence.getId() == null){
            geofence.setCreateTime(new Date());
            geofence.setStatus("1");
            geofenceMapper.insert(geofence);
        }else {
            geofence.setUpdateTime(new Date());
            geofenceMapper.update(geofence);
        }
    }

    @Override
    public void delete(Long id) {
        geofenceMapper.delete(id);
    }

    @Override
    public void updateVehicle(Long id) {
        geofenceMapper.updateVehicle(id);
    }
}
